
package cn.supermaster.management.finance.service.impl;

import cn.supermaster.management.common.domain.SystemDictionaryType;
import cn.supermaster.management.common.page.TableDataInfo;
import cn.supermaster.management.common.response.WebResponse;
import cn.supermaster.management.common.utils.WebHelper;
import cn.supermaster.management.finance.domain.FinanceAccount;

import cn.supermaster.management.finance.mapper.FinanceAccountMapper;
import cn.supermaster.management.finance.service.IFinanceAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * All rights Reserved, Designed By www.super-bytecode.com
 *
 * @ProjectName: XXXXX
 * @Package: cn.supermaster.management.finance.service.impl
 * @ClassName: FinanceAccountServiceImpl
 * @Description: []
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2021-02-21 20:26:09
 * @Version: V1.0
 * @Copyright: 2021 www.super-bytecode.comn Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@Service
public class FinanceAccountServiceImpl implements IFinanceAccountService {

    @Autowired
    private FinanceAccountMapper financeAccountMapper;

    /**
     * @Description: [新增记录]
     * <p></P>
     * @Title: addFinanceAccount
     * @Author: Lance Ting
     * @Date: 2021-02-21
     * @Param: financeAccount 新增的记录
     * @Return: cn.supermaster.management.finance.response.WebResult 返回结果
     */
    @Override
    public WebResponse addFinanceAccount(FinanceAccount financeAccount) {
        WebResponse result = null;
        try {
            // 入库操作
            insertFinanceAccountSelective(financeAccount);
            result = WebResponse.success("新增记录成功！");
        } catch (Exception e) {
            e.printStackTrace();
            result = WebResponse.failure("新增记录失败，" + e.getMessage());
        }
        return result;
    }

    /**
     * @Description: [删除记录（逻辑删除）]
     * <p></P>
     * @Title: remove
     * @Author: Lance Ting
     * @Date: 2021-02-21
     * @Param: accountId 删除的记录id
     * @Return: cn.supermaster.management.finance.response.WebResult 返回结果
     */
    @Override
    public WebResponse removeFinanceAccount(Long accountId) {
        WebResponse result = null;
        try {
            // 删除操作
            deleteFinanceAccount(accountId);
            result = WebResponse.success("删除记录成功！");
        } catch (Exception e) {
            e.printStackTrace();
            result = WebResponse.failure("删除记录失败，" + e.getMessage());
        }
        return result;
    }

    /**
     * @Description: [修改记录]
     * <p></P>
     * @Title: modifyFinanceAccount
     * @Author: Lance Ting
     * @Date: 2021-02-21
     * @Param: financeAccount 修改的记录id
     * @Return: cn.supermaster.management.finance.response.WebResult 返回结果
     */
    @Override
    public WebResponse modifyFinanceAccount(FinanceAccount financeAccount) {
        WebResponse result = null;
        try {
            // 修改操作
            updateFinanceAccountSelective(financeAccount);
            result = WebResponse.success("删除记录成功！");
        } catch (Exception e) {
            e.printStackTrace();
            result = WebResponse.failure("删除记录失败，" + e.getMessage());
        }
        return result;
    }

    /**
     * @Description: [根据主键查询]
     * <p></P>
     * @Title: queryFinanceAccountById
     * @Author: Lance Ting
     * @Date: 2021-02-21
     * @Param: accountId 主键
     * @Return: cn.supermaster.management.finance.response.WebResult 返回结果
     */
    @Override
    public WebResponse queryFinanceAccountById(Long accountId) {
        WebResponse result = null;
        try {
            // 获取记录
            FinanceAccount financeAccount = selectFinanceAccountByPrimaryKey(accountId);
            result = WebResponse.success(financeAccount);
        } catch (Exception e) {
            e.printStackTrace();
            result = WebResponse.failure("根据主键查询失败，" + e.getMessage());
        }
        return result;
    }

    /**
     * @Description: [获取所有数据记录]
     * <p></P>
     * @Title: queryFinanceAccountListByCondition
     * @Author: Lance Ting
     * @Date: 2021-02-21
     * @Return: cn.supermaster.management.finance.response.WebResult 返回结果
     */
    @Override
    public TableDataInfo queryFinanceAccountListByCondition(FinanceAccount account) {
        TableDataInfo dataTable = null;
        try {
            WebHelper.startPage();
            // 获取记录
            List<FinanceAccount> financeAccounts = selectFinanceAccountListByCondition(account);
            dataTable = WebHelper.getDataTable(financeAccounts);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dataTable;
    }

    // ==============================================================
    // 私有方法
    // ==============================================================

    /**
     * @Description: [新增，插入所有字段]
     * <p></P>
     * @Title: insertFinanceAccount
     * @Author: Lance Ting
     * @Date: 2021-02-21
     * @Param: financeAccount 新增的记录
     * @Return: int 返回影响行数
     */
    private int insertFinanceAccountSelective(FinanceAccount financeAccount) {
        return financeAccountMapper.insertFinanceAccountSelective(financeAccount);
    }

    /**
     * @Description: [删除记录（物理删除）]
     * <p></P>
     * @Title: delete
     * @Author: Lance Ting
     * @Date: 2021-02-21
     * @Param: financeAccount 待删除的记录id
     * @Return: int 返回影响行数
     */
    private int delete(Long accountId) {
        return financeAccountMapper.delete(accountId);
    }

    /**
     * @Description: [删除记录（逻辑删除）]
     * <p>修改status状态=0</P>
     * @Title: deleteFinanceAccount
     * @Author: Lance Ting
     * @Date: 2021-02-21
     * @Param: financeAccount 待删除的记录id
     * @Return: int 返回影响行数
     */
    private int deleteFinanceAccount(Long financeAccount) {
        return financeAccountMapper.deleteFinanceAccount(financeAccount);
    }

    /**
     * @Description: [修改，修改非空字段]
     * <p></P>
     * @Title: modifyFinanceAccountSelective
     * @Author: Lance Ting
     * @Date: 2021-02-21
     * @Param: financeAccount 修改的记录id
     * @Return: int 返回影响行数
     */
    private int updateFinanceAccountSelective(FinanceAccount financeAccount) {
        return financeAccountMapper.updateFinanceAccountSelective(financeAccount);
    }

    /**
     * @Description: [根据主键查询]
     * <p></P>
     * @Title: selectFinanceAccountByPrimaryKey
     * @Author: Lance Ting
     * @Date: 2021-02-21
     * @Param: financeAccount 主键
     * @Return: cn.supermaster.management.finance.domain.FinanceAccount 返回记录，没有返回null
     */
    private FinanceAccount selectFinanceAccountByPrimaryKey(Long accountId) {
        return financeAccountMapper.selectFinanceAccountByPrimaryKey(accountId);
    }

    /**
     * @Description: [查询所有记录]
     * <p></P>
     * @Title: selectFinanceAccountByPrimaryKey
     * @Author: Lance Ting
     * @Date: 2021-02-21
     * @Return: cn.supermaster.management.finance.domain.FinanceAccount 返回记录，没有返回null
     */
    private List<FinanceAccount> selectFinanceAccountList() {
        return financeAccountMapper.selectFinanceAccountList();
    }

    /**
     * @Description: [根据条件查询]
     * <p></P>
     * @Title: selectFinanceAccountListByCondition
     * @Author: Lance Ting
     * @Date: 2021-02-21
     * @Param: financeAccount 主键
     * @Return: List<cn.supermaster.management.finance.domain.FinanceAccount> 返回记录，没有返回null
     */
    private List<FinanceAccount> selectFinanceAccountListByCondition(FinanceAccount financeAccount) {
        return financeAccountMapper.selectFinanceAccountListByCondition(financeAccount);
    }
}